#ifndef TCP_H
#define TCP_H
#include "threadPool.h"
#include "util.h"

#define STATE_FREE 0
#define STATE_BUSY 1

typedef struct conn_info_s {
  int netfd;
  char user_name[1024];
  int state;
  int is_alive;
  struct sockaddr_in addr;
} conn_info;

typedef struct tlv {
  ssize_t len;
  char data[4096];
  char jwt[JWT_LEN + 1];
} TLV;
// ssize_t recvn(int fd, void* buf, ssize_t length);

int tcp_init(char *ip, char *port);
// void send_tlv(int netfd, void *buf, ssize_t len);
ssize_t send_tlv(int netfd, const void *buf, ssize_t len);

ssize_t recv_tlv(int netfd, TLV *tlv);
void send_err(int netfd, const char *msg);

void *cd_c(void *arg, MYSQL *conn);
void *ls_c(void *arg, MYSQL *conn);
void *puts_c(void *arg, MYSQL *conn);
void *gets_c(void *arg, MYSQL *conn);
void *pwd_c(void *arg, MYSQL *conn);
void *mkdir_c(void *arg, MYSQL *conn);
void *rmdir_c(void *arg, MYSQL *conn);
void *login_c(void *arg, MYSQL *conn);
void *sign_up_c(void *arg, MYSQL *conn);
void *tree_c(void *arg, MYSQL *conn);

int getPath_c(void *arg, MYSQL *conn);
#endif